---
title: "Squalus acanthias ETN detections overview"
output:
flexdashboard::flex_dashboard:
source_code: embed
orientation: rows
vertical_layout: scroll
theme:
version: 4
bootswatch: litera
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE, echo = F}
# knitr::opts_chunk$set(echo = F)
# Sys.setlocale("LC_TIME", "English") # language = English, does not work right now
# fundamentals
library(flexdashboard)
library(etn)
library(knitr)
# data wrangling
library(readr)
# library(tidyverse)
library(lubridate)
library(dplyr)
library(lubridate)
library(utils)
library(forcats)
# maps
library(leaflet)
library(leafem)
# plotting and tables
library(DT) # for interactive tables
library(ggplot2)
library(kableExtra)
library(plotly)
library(scico) #colour palettes
# database connection
con <- etn::connect_to_etn(Sys.getenv("userid"), Sys.getenv("pwd"))
```
```{r database query, include=FALSE, echo=FALSE}
```
<!-- Overview: Receiver stations -->
<!-- ===================================== -->
Row {data-height=1000}
-------------------------------------
### Map with receivers that detected S. acanthias
```{r map}
#, include=T, echo=F
# EMODnet Bathymetry layer
# emodnet_tiles <-"https://tiles.emodnet-bathymetry.eu/2020/baselayer/web_mercator/{z}/{x}/{y}.png"
# cite_emodnet <- "<a href='https://emodnet.ec.europa.eu'>EMODnet</a>"
# attr(cite_emodnet, "class") <- c("html", "character")
#
# # special icons
# # a single icon is declared
# icon_tag <- leaflet::makeAwesomeIcon(
# icon = "tag",
# iconColor = "black",
# markerColor = "yellow",
# library = "fa"
# )
# colour palettes
# col_fun <- scico::scico(n = stations$deploy_latitude %>% unique() %>% length(),
# palette = "roma")
# pal <- leaflet::colorFactor(col_fun, domain = stations$deploy_latitude)
# qpal <- colorQuantile(col_fun, domain = stations$deploy_latitude, n = 5)
# palette_latitudes_df <- tibble(deploy_latitude = stations$deploy_latitude, color = pal(stations$deploy_latitude))
#
#
# legend_latitudes <- stations %>%
# dplyr::mutate(bin_n5 = deploy_latitude %>% dplyr::ntile(n = 5)) %>%
# dplyr::group_by(bin_n5) %>%
# dplyr::summarise(min = deploy_latitude %>% min(),
# max = deploy_latitude %>% max()) %>%
# dplyr::mutate(color = qpal(stations$deploy_latitude) %>% unique())
#
# leaflet() %>%
#
# #background
# # addTiles() %>%
# addProviderTiles("Esri.WorldImagery", options = providerTileOptions(opacity = 0.6), group = "satellite") %>%
# leaflet::addTiles(urlTemplate = emodnet_tiles,
# # options = leaflet::tileOptions(tms = FALSE),
# attribution = cite_emodnet,
# group = "EMODnet bathymetry") %>%
# # addRasterImage(bathy_belgium_raster, opacity = 1, colors = "Spectral", group = "bathymetry") %>%
# # addPolygons(data = coastline_BE_poly, opacity = 1, fillColor = "grey", weight = 0, fillOpacity = 0.7, group = "bathymetry") %>% #"#ECE4BF"
# addTiles(group = "OpenStreetMap") %>%
#
# #data: receiver stations
# addCircleMarkers(data = stations,
# # clusterOptions = markerClusterOptions(showCoverageOnHover = F, zoomToBoundsOnClick = T, freezeAtZoom = 7),
# lat = ~deploy_latitude,
# lng = ~deploy_longitude,
# radius = 5,
# color = "black",
# weight = 1,
# fillOpacity = 1,
# fillColor = ~pal(deploy_latitude),
# opacity = 1,
# label = ~paste0("station ", station_name),
# popup = ~paste0("lat: ", deploy_latitude, ", lon: ", deploy_longitude),
# group = "receiver stations"
# ) %>%
#
# #data: tagging locations
# addAwesomeMarkers(data = tagging_locations,
# icon = icon_tag,
# clusterOptions = markerClusterOptions(), #showCoverageOnHover = T, zoomToBoundsOnClick = T,
# lat = ~releaseLatitude,
# lng = ~releaseLongitude,
# # radius = 5,
# # fillOpacity = 0.7,
# # fillColor = "yellow",
# # opacity = 0,
# label = ~paste0("name: ", tagging_location),
# popup = ~paste0("lat: ", releaseLatitude, ", lon: ", releaseLongitude, ", #sharks tagged: ", ind_tagged),
# group = "tagging locations"
# ) %>%
#
# # add-ons
# leaflet.extras::addFullscreenControl() %>%
# leafem::addMouseCoordinates() %>%
# addScaleBar(position = "bottomright",
# options = scaleBarOptions(
# maxWidth = 150,
# imperial = FALSE)) %>%
#
# # layers control
# addLayersControl(position = "topright" ,
# baseGroups = c("EMODnet bathymetry", "satellite", "OpenStreetMap"),
# overlayGroups = c("receiver stations", "tagging locations"),
# options = layersControlOptions(collapsed = FALSE)) %>%
# hideGroup("tagging locations") %>%
#
# # legend
# addLegend(position = "bottomleft",
# colors = legend_latitudes$color %>% rev(),
# labels = paste0(legend_latitudes$min %>% round(), " - ", legend_latitudes$max %>% round()) %>% rev(),
# opacity = 1,
# title = "Latitude")
# MWE
# leaflet() %>%
# addTiles() %>%
# addCircleMarkers(data = stations,
# lat = ~deploy_latitude,
# lng = ~deploy_longitude,
# color = ~pal2(deploy_latitude)) %>%
# addLegend(position = "bottomleft",
# colors = legend_latitudes$color,
# labels = paste0(legend_latitudes$min %>% round(), " - ", legend_latitudes$max %>% round()),
# opacity = 1,
# title = "Latitude")
```
<!-- > Map with receiver deployments and acoustic detections. -->
### side row?
```{r abacus}
```
Row {data-height=1000}
-------------------------------------
### Table
```{r table}
# DT::datatable(animals %>%
# dplyr::select(idPk, catchedDateTime, tagging_location, utcReleaseDateTime, sex, tag, releaseLatitude, releaseLongitude),
# rownames = F,
# filter = 'bottom',
# extension = 'Buttons',options = list(
# dom = 'Bfrtip',
# buttons = c('pdf', 'csv', 'excel', 'print','copy'),
# columnDefs = list(list(className = 'dt-center', targets = '_all'))
# )
# )
#
# ))
# options = list(pageLength = 10, autoWidth = TRUE, columnDefs = list(list(className = 'dt-center', targets = '_all')))
# )
# %>%
# formatStyle(
# c('receiver_id', 'battery_estimated_end_date'),
# fontWeight = "bold") %>%
# formatStyle(
# 'needs_battery_change',
# backgroundColor = styleEqual(c(0, 1), c('#90BF87', '#F9938E')))
```
<!-- Details: Acoustic Projects & Detections -->
<!-- ===================================== -->